//
//  ByMyHeadView.m
//  caipiao_ios
//
//  Created by mc on 2018/7/4.
//  Copyright © 2018年 ZhangZhanbin. All rights reserved.
//

#import "ByMyHeadView.h"


@implementation ByMyHeadView

- (id)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        UIImageView *backgroundView = [[UIImageView alloc] init];
        [self addSubview:backgroundView];
        [backgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(0);
            make.right.equalTo(self).offset(0);
            make.top.equalTo(self).offset(0);
            make.bottom.equalTo(self).offset(0);
        }];
        backgroundView.image = [UIImage imageNamed:@"beijing"];
        backgroundView.userInteractionEnabled = YES;
        
        
        UIImageView *iconView = [[UIImageView alloc] init];
        [backgroundView addSubview:iconView];
        [iconView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(backgroundView).offset(22);
            make.bottom.equalTo(backgroundView).offset(-90);
            make.size.mas_equalTo(CGSizeMake(70, 70));
        }];
        iconView.layer.cornerRadius = 35;
        iconView.layer.masksToBounds = YES;
        iconView.image = [UIImage imageNamed:@"yonghutouxinag"];
        iconView.userInteractionEnabled = YES;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
        [iconView addGestureRecognizer:tap];
        
        
        UILabel *nameLabel = [[UILabel alloc] init];
        [backgroundView addSubview:nameLabel];
        [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(iconView.mas_top).offset(10);
            make.left.equalTo(backgroundView).offset(110);
            make.right.equalTo(backgroundView).offset(-100);
            make.height.mas_equalTo(@18);
        }];
        nameLabel.textColor = [UIColor whiteColor];
        nameLabel.textAlignment = NSTextAlignmentLeft;
        nameLabel.font = FONT(16);
        nameLabel.text = @"";
        
        
        UIButton *setBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [backgroundView addSubview:setBtn];
        [setBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(backgroundView).offset(-10);
            make.top.equalTo(iconView.mas_top).offset(0);
            make.size.mas_equalTo(CGSizeMake(20, 20));
        }];
        [setBtn setImage:[UIImage imageNamed:@"shehzi"] forState:UIControlStateNormal];
        [setBtn addTarget:self action:@selector(setAction:) forControlEvents:UIControlEventTouchUpInside];
        
        
        UIButton *certificationBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [backgroundView addSubview:certificationBtn];
        [certificationBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(backgroundView).offset(10);
            make.top.equalTo(iconView.mas_top).offset(0);
            make.size.mas_equalTo(CGSizeMake(80, 30));
        }];
        [certificationBtn setTitle:@"未实名认证" forState:UIControlStateNormal];
        certificationBtn.titleLabel.font = FONT(14);
        [certificationBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        certificationBtn.layer.borderColor = [UIColor whiteColor].CGColor;
        certificationBtn.layer.borderWidth = 1;
        certificationBtn.layer.cornerRadius = 3;
        [certificationBtn addTarget:self action:@selector(certificateAction:) forControlEvents:UIControlEventTouchUpInside];
        certificationBtn.hidden = YES;
        
        
        ByHomeTitleValueView *leftView = [[ByHomeTitleValueView alloc] init];
        [backgroundView addSubview:leftView];
        [leftView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(backgroundView).offset(0);
            make.bottom.equalTo(backgroundView).offset(0);
            make.size.mas_equalTo(CGSizeMake((SCREEN_WIDTH - 1) / 2.0, 70));
        }];
        leftView.titleLabel.text = @"可用余额(元)";
        leftView.valueLabel.text = @"0.00";
        
        ByHomeTitleValueView *rightView = [[ByHomeTitleValueView alloc] init];
        [backgroundView addSubview:rightView];
        [rightView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(backgroundView).offset(0);
            make.bottom.equalTo(backgroundView).offset(0);
            make.size.mas_equalTo(CGSizeMake((SCREEN_WIDTH - 1) / 2.0, 70));
        }];
        rightView.titleLabel.text = @"可提现余额(元)";
        rightView.valueLabel.text = @"0.00";
        
        
        UIView *grayView = [[UIView alloc] init];
        [backgroundView addSubview:grayView];
        [grayView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(backgroundView).offset(0);
            make.right.equalTo(backgroundView).offset(0);
            make.bottom.equalTo(backgroundView).offset(0);
            make.height.mas_equalTo(@70);
        }];
        grayView.backgroundColor = rgba(0, 0, 0, 0.1);
        
        
        UILabel *focusLabel = [[UILabel alloc] init];
        [backgroundView addSubview:focusLabel];
        [focusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(nameLabel.mas_left).offset(0);
            make.top.equalTo(nameLabel.mas_bottom).offset(10);
            make.size.mas_equalTo(CGSizeMake(90, 20));
        }];
        focusLabel.textColor = [UIColor whiteColor];
        focusLabel.font = FONT(14);
        focusLabel.tag = 100;
        focusLabel.userInteractionEnabled = YES;
        focusLabel.text = @"关注：";
        self.focusLabel = focusLabel;
        
        UILabel *fansLabel = [[UILabel alloc] init];
        [backgroundView addSubview:fansLabel];
        [fansLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(focusLabel.mas_right).offset(0);
            make.top.equalTo(focusLabel.mas_top).offset(0);
            make.right.equalTo(backgroundView).offset(-20);
            make.height.mas_equalTo(@20);
        }];
        fansLabel.textColor = [UIColor whiteColor];
        fansLabel.font = FONT(14);
        fansLabel.tag = 200;
        fansLabel.userInteractionEnabled = YES;
        fansLabel.text = @"粉丝：";
        self.fansLabel = fansLabel;
        
        UILabel *line = [[UILabel alloc] init];
        [backgroundView addSubview:line];
        [line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(backgroundView).offset(-15);
            make.centerX.equalTo(backgroundView).offset(0);
            make.size.mas_equalTo(CGSizeMake(1, 40));
        }];
        line.backgroundColor = [UIColor whiteColor];
        
        self.iconView = iconView;
        self.nameLabel = nameLabel;
        self.leftView = leftView;
        self.rightView = rightView;
        
        UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(focusFansAction:)];
        [focusLabel addGestureRecognizer:tap1];
        
        UITapGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(focusFansAction:)];
        [fansLabel addGestureRecognizer:tap2];
        
    }
    return self;
}

- (void)focusFansAction:(UITapGestureRecognizer *)tap{
    if (tap.view.tag == 100) {
        if (self.focusBlock) {
            self.focusBlock();
        }
        
    }else if (tap.view.tag == 200){
        if (self.fansBlock) {
            self.fansBlock();
        }
        
    }
    
}



- (void)setAction:(UIButton *)btn{
    NSLog(@"设置");
    if (self.setBlock) {
        self.setBlock();
    }
}

- (void)certificateAction:(UIButton *)btn{
    NSLog(@"实名认证");
    if (self.certificateBlock) {
        self.certificateBlock();
    }
}

- (void)tapAction:(UITapGestureRecognizer *)tap{
    
    if (self.tapViewBlock) {
        self.tapViewBlock();
    }
}


@end
